/**
 * Created by Mr.Xing on 2018/10/16.
 */
mini.parse();
mini_debugger = false;
var grid = mini.get("tableClass");
// grid.load(ajaxUrl + "/tableClass/list.do");
grid.load();
var url = bootPATH + "../frame/frame1/pages/formLayout";

// var attr = [{ id: 1, text: '表头' }, { id: 2, text: '表体'}];
// var edit = [{ id: 1, text: '是' }, { id: 2, text: '否'}];
var pro_temp = [];
var properties = [];//存放属性
var properties_form = [];//存放属性
var properties_table = [];//存放属性
var fItems = [];//存放组件数据
var fuzhu_temp = [];
var table_data = [];

mini.parse();

var grid = mini.get("tableClass");
grid.load();

//查询
function search() {

    var row = grid.getSelected();

    var layoutMode = mini.get("layoutMode");
    var layout = layoutMode.getValue();

    if (layout == null || layout == "") {
        mini.alert("请先选择布局方式");
    } else if (row) {
        mini.open({
            url: bootPATH + "../frame/frame1/pages/formLayout/tableFieldList.html",
            title: "选择需要布局的字段",
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {
                    action: "edit", id: row.tableClassId, layoutMode: layout
                };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {//关闭之前执行
                // if (action == "close") return false;
                // alert(1);
                // console.log(action);
                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.onTableOk();
                    // data = mini.clone(data);
                    console.log(data);

                    //获取数据库表名字段
                    var tableClass = mini.get("tableClass");
                    var rows = tableClass.getSelecteds();

                    if(layout == '表格布局'){
                        console.log('表格布局');
                        createTable(data);
                        for(var i=0;i<data.length;i++){
                            properties_table.push({
                                id : data[i].field,
                                cLadText: data[i].fieldCh,
                                cTableField: data[i].field,
                                cTableName: rows[0].tableClassName,
                                cFormName: rows[0].tableChClassName,
                                type: "table"
                            });
                        }
                        properties_table = reduce(properties_table,'id');
                        console.log(properties_table,'properties_table');
                    }else {
                        console.log('自由布局');
                        for(var i=0;i<data.length;i++){
                            gridbeforeselect(data[i]);
                            properties_form.push({
                                id : data[i].field,
                                cTableField: data[i].field,
                                cLadText: data[i].fieldCh,
                                cTableName: rows[0].tableClassName,
                                cFormName: rows[0].tableChClassName,type: "form" });
                        }
                        properties_form = reduce(properties_form,'id');
                        console.log(properties_form,'properties_form');
                    }
                }
            }
        });
    } else {
        mini.alert("请选择一条记录");
    }
}

//生成表格
var i = 0;
function createTable(data) {
    console.log(data, '表格字段');
     var t = [];
     var flag = 0;
     // var bool = [];
     for(var i=0;i<properties_table.length;i++) {
         t.push(properties_table[i].id);
         for (var j = 0; j < data.length; j++) {
             console.log($.inArray(data[j].field, t), '---');
             // bool.push($.inArray(data[j].field, t));
             if($.inArray(data[j].field, t) != -1) {
                 flag = 1;
             }
         }
     }
     if(flag != 1) { //不重复
        i++;
        // var id = "tableCreated" + data[0].tableName;
        var id = "tableCreated" + data[0].tableName + i;
        var sth = "<table id='" + id + "' class='tableCreated' border='1' cellpadding='0' cellspacing='0'>\n";
        sth += "<thead><tr>";
        for (var i = 0; i < data.length; i++) {
            sth += "<th id='th" + data[i].field + "'>" + data[i].fieldCh + "</th>";
        }
        sth += "</tr><tbody>";
        for (var i = 0; i < 3; i++) {
            sth += "<tr>";
            for (var j = 0; j < data.length; j++) {
                sth += "<td>" + " " + "</td>";
            }
            sth += "</tr></thead>";
        }
        $("#formTable").append(sth + "</tbody></table>");

        $( "#" + id ).draggable({
            containment: "#formTable",
            scroll: false,
            cursor: "move",
            // start: function() {
            //     $(this).css({"cursor":"move"});
            // }
        });
        $( "#" + id ).resizable({ containment: "#formTable"});
        $( ".tableCreated thead tr" ).sortable();
        $( "#" + id ).disableSelection();

     }

    var $item = $( "table thead tr th" );
    $item.click(tableclick);//点击事件

}

//生成表单组件
function gridbeforeselect(sender) {
    console.log(sender,'sender');
    // var flag = JSON.stringify(properties_form).indexOf(JSON.stringify(sender));
    // console.log(flag);
    var t = [];
    for(var i=0;i<properties_form.length;i++){
        t.push(properties_form[i].id);
    }
    console.log($.inArray(sender.field, t),'---');
    if($.inArray(sender.field, t) == -1){
        //不重复
        createGrid();
    }

    function createGrid() {
            var id = sender.field;
            // var id = sender.field + sender.tableId;
            $("#formTable").append("<div class='fuzhu' id='" + id + "' title='" + sender.field + "'>" +
                "<li style='width: 95px;float: left;height: 100%;background: #ccc;overflow: hidden;text-align: center;line-height: 40px;' id='li" + id + "'>" + sender.fieldCh + "</li>" +
                "<label class='lab1' id='lab" + id + "'></label>" +
                "<input id='k" + id + "' type='text' mytype='text' style='left:98px;height:100%;position: absolute;width:100px;'>" +
                "</div>");
            $item = $("#" + id);
            $item.click(fuzhuclick);//点击事件
            $item.resizable({
                handles: 'n, e, s, w, ne, se, sw, nw',
                grid: [20, 20],
                resize: function () {
                    $('#li' + $(this).attr('id')).css('line-height', $('#li' + $(this).attr('id')).height() + 'px');
                    console.log($(this).width() - $('#li' + $(this).attr('id')).width() - 3 + 'px');
                    $('#k' + $(this).attr('id')).css('width', $(this).width() - $('#li' + $(this).attr('id')).width() - 3 + 'px')
                }
            });
            var clickX, leftOffset;
            var dragging = false;
            var labBtn = $('#lab' + id);
            //按下鼠标
            labBtn.bind('mousedown', function (e) {
                    dragging = true;
                    // console.log($(this).attr('id'));
                    leftOffset = $('#' + $(this).attr('id').substring(3)).offset().left;//左坐标
                    $('#' + $(this).attr('id').substring(3)).draggable('disable');
                    //按下并拖动鼠标
                    $('#' + $(this).attr('id').substring(3)).bind('mousemove', function (e) {
                        clickX = e.pageX;
                        console.log(e.pageX);
                        $('#li' + $(this).attr('id')).css('width', clickX - 7 - leftOffset + 'px');
                        $('#lab' + $(this).attr('id')).css('left', clickX - 7 - leftOffset + 'px');
                        $('#k' + $(this).attr('id')).css('left', clickX - 4 - leftOffset + 'px');
                        $('#k' + $(this).attr('id')).css('width', $(this).width() - clickX + 4 + leftOffset + 'px');
                    })
                    e.stopPropagation();
                }
            );

            $item.mouseup(function (e) {
                $('#' + $(this).attr('id')).unbind('mousemove');
                $('#' + $(this).attr('id')).draggable('enable');
                dragging = false;
            })
            $item.css("position", "absolute");
            $item.draggable({
                grid: [20, 20],
                containment: "parent",
                snap: true,
                snapTolerance: 20,
                start: function () {

                },
                stop: function () {

                }
            });
    }
    // if (flag) {
    //     var id = sender.field + sender.tableId;
    //
    //     $("#formTable").append("<div class='fuzhu' id='" + id + "' title='" + sender.field + "'>" +
    //         "<li style='width: 95px;float: left;height: 100%;background: #ccc;overflow: hidden;text-align: center;line-height: 40px;' id='li" + id + "'>" + sender.fieldCh + "</li>" +
    //         "<label class='lab1' id='lab" + id + "'></label>" +
    //         "<input id='k" + id + "' type='text' mytype='text' style='left:98px;height:100%;position: absolute;width:100px;'>" +
    //         "</div>");
    //     $item = $("#" + id);
    //     $item.click(fuzhuclick);//点击事件
    //     $item.resizable({
    //         handles: 'n, e, s, w, ne, se, sw, nw',
    //         grid: [20, 20],
    //         resize: function () {
    //             $('#li' + $(this).attr('id')).css('line-height', $('#li' + $(this).attr('id')).height() + 'px');
    //             console.log($(this).width() - $('#li' + $(this).attr('id')).width() - 3 + 'px');
    //             $('#k' + $(this).attr('id')).css('width', $(this).width() - $('#li' + $(this).attr('id')).width() - 3 + 'px')
    //         }
    //     });
    //     var clickX, leftOffset;
    //     var dragging = false;
    //     var labBtn = $('#lab' + id);
    //     //按下鼠标
    //     labBtn.bind('mousedown', function (e) {
    //             dragging = true;
    //             // console.log($(this).attr('id'));
    //             leftOffset = $('#' + $(this).attr('id').substring(3)).offset().left;//左坐标
    //             $('#' + $(this).attr('id').substring(3)).draggable('disable');
    //             //按下并拖动鼠标
    //             $('#' + $(this).attr('id').substring(3)).bind('mousemove', function (e) {
    //                 clickX = e.pageX;
    //                 console.log(e.pageX);
    //                 $('#li' + $(this).attr('id')).css('width', clickX - 7 - leftOffset + 'px');
    //                 $('#lab' + $(this).attr('id')).css('left', clickX - 7 - leftOffset + 'px');
    //                 $('#k' + $(this).attr('id')).css('left', clickX - 4 - leftOffset + 'px');
    //                 $('#k' + $(this).attr('id')).css('width', $(this).width() - clickX + 4 + leftOffset + 'px');
    //             })
    //             e.stopPropagation();
    //         }
    //     );
    //
    //     $item.mouseup(function (e) {
    //         $('#' + $(this).attr('id')).unbind('mousemove');
    //         $('#' + $(this).attr('id')).draggable('enable');
    //         dragging = false;
    //     })
    //     $item.css("position", "absolute");
    //     $item.draggable({
    //         grid: [20, 20],
    //         containment: "parent",
    //         snap: true,
    //         snapTolerance: 20,
    //         start: function () {
    //
    //         },
    //         stop: function () {
    //
    //         }
    //     });
    // } else {
    //     // var id = sender.records[0].cTab_EN_Name + sender.records[0].id;
    //     // $("#" + id).remove();
    // }
    //
    // var formTable = $("#formTable").children();
    // console.log(formTable,'formTable');
    // for(var i = 0; i < formTable.length; i++){
    //     fItems[i] = {
    //         cEditCss: formTable[i].className,
    //         cLadText: formTable[i].innerText, cTableField: formTable[i].title,
    //         iConX: formTable[i].offsetLeft, iConY: formTable[i].offsetTop,
    //         iLabHeight: formTable[i].offsetHeight, iWidth: formTable[i].offsetWidth,
    //         iLabWidth: formTable[i].children[2].offsetWidth
    //     };
    // }
    // fItems = reduce(fItems,'cTableField');
    // console.log(fItems,'控件的数据');
}

//点击组件
var temp=[];
var click_type;
var click_types = [];
var click_ids = [];
var thisTitle;
function fuzhuclick() {
    click_type = "form";
    click_types.push("form");
    var pre_click_type = click_types.slice(-2, -1).toString();//上一个需要存起来的属性的类型,为空则为第一次点击，不存储
    // console.log(properties_form,'属性数组');
    var thisId = $(this).attr('id');
    click_ids.push(thisId);
    var pre_click_id = click_ids.slice(-2, -1).toString();//上一个需要存起来的属性的id

    savePre(pre_click_type,thisId,pre_click_id);

    // thisTitle = $(this).attr('title');
    // // $('#shuxing').html($('#li' + thisid).html() + '属性');
    // console.log($(this),'选择的组件');
    //
    // temp.push(thisTitle);//点过击的id数组
    // var preTitle = temp.slice(-2, -1).toString();//数组倒数第二个id（需存储的上一个id）
    // console.log(preTitle,'-存储的上一个id-');
    // var pre = mini.decode(getForm());
    // console.log(pre,'pre');
    // pre.id = preTitle;//设置属性数组的id
    // console.log(thisTitle,'选择的id');
    // for(var i=0;i<properties_form.length;i++){
    //     //存储上一张表单信息
    //    if(preTitle == properties_form[i].id) {
    //        // properties[i] = pre;
    //        $.extend(properties_form[i],{"cRefObj":pre});
    //        console.log(properties_form,'已存储pre');
    //     }
    //     //显示当前表单信息
    //     //保存时还需要保存一次表单信息
    //    if(thisTitle == properties_form[i].id) {
    //        console.log(properties_form[i],'设置的属性');
    //        resetForm();
    //        setForm(properties_form[i].cRefObj);
    //    }
    // }
}
//点击表格
function tableclick() {
    console.log($(this),'---');

    click_type = "table";
    click_types.push("table");
    var pre_click_type = click_types.slice(-2, -1).toString();//上一个需要存起来的属性的类型

    // var headhname = $(this)[0]['innerHTML'];//表头字段
    // console.log(headhname,'headhname');
    var id = $(this)[0]['id'];//表头字段id
    id = id.substring(2);//取去掉th
    console.log(id,'id');

    click_ids.push(id);
    var pre_click_id = click_ids.slice(-2, -1).toString();//上一个需要存起来的属性的id
    savePre(pre_click_type,id,pre_click_id);

    //
    // table_data.push({
    //     "id": id,
    //     "tableName": data[0].tableName
    // });
    // console.log(table_data);
}
var id_now;
function savePre(pre_type,id,pre_id) {
    console.log(pre_type,'需存储的上一个的类型');
    console.log(pre_id,'需存储的上一个的id');
    console.log('点击了',click_type);
    id_now = id;
    console.log('当前id',id_now);
    console.log('properties_table',properties_table);

    //点击表单
    if( click_type == "form") {
        //数据存到表单属性数组properties_form
        //存储上一张表单信息
        var pre = mini.decode(getForm());
        pre.id = id;//设置属性数组的id
        console.log(pre,'需存储的上一个的数据');
        if(pre_type == "form") {
            for(var i=0;i<properties_form.length;i++){
                if(pre_id == properties_form[i].id) {
                    $.extend(properties_form[i],{"cRefObj":pre});
                    console.log(properties_form,'已存储pre form');
                }
            }
        }else if(pre_type == "table") {
            for(var i=0;i<properties_table.length;i++){
                if(pre_id == properties_table[i].id) {
                    $.extend(properties_table[i], {"cRefObj": pre});
                    console.log(properties_table, '已存储pre table');
                }
            }
        }
        //显示当前表单信息
        //保存时还需要保存一次表单信息
        for(var i=0;i<properties_form.length;i++){
           if(id == properties_form[i].id) {
               console.log(properties_form[i],'需要显示的属性');
               resetForm();
               setForm(properties_form[i].cRefObj);
           }
        }

    }else if ( click_type == "table") {
        //数据存到表单属性数组properties_table
        //存储上一张表单信息
        var pre = mini.decode(getForm());
        pre.id = id;//设置属性数组的id
        console.log(pre,'需存储的上一个的数据');
        if(pre_type == "form") {
            for(var i=0;i<properties_form.length;i++){
                if(pre_id == properties_form[i].id) {
                    $.extend(properties_form[i],{"cRefObj":pre});
                    console.log(properties_form,'已存储pre form');
                }
            }
        }else if(pre_type == "table") {
            for(var i=0;i<properties_table.length;i++){
                if(pre_id == properties_table[i].id) {
                    $.extend(properties_table[i], {"cRefObj": pre});
                    console.log(properties_table, '已存储pre table');
                }
            }
        }
        //显示当前表单信息
        //保存时还需要保存一次表单信息
        for(var i=0;i<properties_table.length;i++){
            if(id == properties_table[i].id) {
                console.log(properties_table[i],'需要显示的属性');
                resetForm();
                setForm(properties_table[i].cRefObj);
            }
        }

    }

}
//保存
function add(){
    //存储上一张表单信息
    var last = mini.decode(getForm());//最后一个控件的数据；
    var last_id = click_ids[click_ids.length-1];//最后一个点击的id
    console.log(last_id,'最后一个点击的id');
    last.id = last_id;//设置属性数组的id

    if(click_type == "form") {
        for(var i=0;i<properties_form.length;i++){
            if(last_id == properties_form[i].id) {
                $.extend(properties_form[i],{"cRefObj":last});
                console.log(properties_form,'已存储last form');
            }
        }
    }else if(click_type == "table") {
        for(var i=0;i<properties_table.length;i++){
            if(last_id == properties_table[i].id) {
                $.extend(properties_table[i], {"cRefObj": last});
                console.log(properties_table, '已存储last table');
            }
        }
    }

    console.log(properties_form,'last form');
    console.log(properties_table, 'last table');

    //控件 位置等数据
    var formTable = $("#formTable").children();
    console.log(formTable,'formTable');
    for(var i = 0; i < formTable.length; i++){
        fItems[i] = {
            cEditCss: formTable[i].className,
            // cTableField: formTable[i].title,
            title: formTable[i].title,
            iConX: formTable[i].offsetLeft, iConY: formTable[i].offsetTop,
            iLabHeight: formTable[i].offsetHeight, iWidth: formTable[i].offsetWidth,
            iLabWidth: formTable[i].children[2].offsetWidth,
            thead: formTable[i].innerText.replace(/[\r\n]/g,""),
            type: formTable[i].localName
        };
        if(fItems[i].type == 'div'){
            fItems[i].type = 'form';
        }
    }
    // fItems = reduce(fItems,'cTableField');
    console.log(fItems,'位置信息数组 fItems');

    //表单合并
    var form_data = [];
    for(var i=0;i<properties_form.length;i++){
        for(var j=0;j<fItems.length;j++){
            if(properties_form[i].cTableField == fItems[j].title &&fItems[j].type == 'form'){
                // properties_form[i]= {'cRefObj':properties_form[i]};
                form_data[i] = $.extend({},properties_form[i],fItems[j]);
            }
        }
    }
    for(var i=0;i<form_data.length;i++){
        form_data[i].cType = form_data[i].cRefObj.cType;
    }

    //表格合并
    var table_data = [];
    for(var i=0;i<properties_table.length;i++){
        for(var j=0;j<fItems.length;j++){
            if(fItems[j].thead.indexOf(properties_table[i].cLadText) >= 0 &&fItems[j].type == 'table'){
                // properties_table[i]= {'cRefObj':properties_table[i]};
                table_data[i] = $.extend({},properties_table[i],fItems[j]);
            }
        }
    }
    for(var i=0;i<table_data.length;i++){
        table_data[i].cType = table_data[i].cRefObj.cType;
    }

    console.log(form_data,'form_data');
    console.log(table_data,'table_data');

    //全部合并
    // var arr_save = $.extend({},form_data,table_data);
    var arr_save = [];
    for(var i=0;i<form_data.length;i++) {
        arr_save.push(form_data[i]);
    }
    for(var i=0;i<table_data.length;i++) {
        arr_save.push(table_data[i]);
    }
    var t = mini.get("fname");//表单名称

    //增加参照字段
    for(var i=0;i<arr_save.length;i++) {
        arr_save[i].cFormName = t.getValue();//表单名cFormName为input中填写
        arr_save[i].cRefObj.dbSourse = arr_save[i].dbSourse;
        arr_save[i].cRefObj.reference = arr_save[i].reference;
        arr_save[i].lanyoutMent = arr_save[i].cRefObj.lanyoutMent;
    }
    // 删除部分字段;
    for(var i=0;i<arr_save.length;i++) {
        delete arr_save[i].id;
        delete arr_save[i].dbSourse;
        delete arr_save[i].reference;
    }
    console.log(arr_save,'arr_save');

    //表单验证
    var form1 = new mini.Form("#fname");
    var form2 = new mini.Form("#dataType");
    form1.validate();
    form2.validate();
    if (form1.isValid() == false) {
        alert('表单名称不能为空');
        return;
    }
    if (form2.isValid() == false) {
        alert('请选择参照类型');
        return;
    }

    //传数据
    var data = JSON.stringify(arr_save);
    // console.log(data);
    var url =  ajaxUrl + "/formltems/insertForm.do";
    $.ajax({
        type : 'POST',
        url : url,
        dataType : 'json',
        contentType: "application/json",
        data : data,
        success: function (data) {
            alert('保存成功！');
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert('保存失败！');
            // console.log(jqXHR);
        }
    })
}

//数组去重
function reduce(arr,type) {
    var hash = {};
    arr = arr.reduce(function(item, next) {
        hash[next[type]] ? '' : hash[next[type]] = true && item.push(next);
        return item
    }, [])
    // console.log(arr,'属性数组');
    return arr;
}

//表单操作
function getForm() {
    var form = new mini.Form("#form1");
    var data = form.getData(true, false);
    var s = mini.encode(data);
    return s;
    // alert(s);
    //form.setIsValid(false);
}
function setForm(obj) {
    var form = new mini.Form("#form1");
    form.setData(obj, false);
}
function resetForm() {
    var form = new mini.Form("#form1");
    form.reset();
}
function clearForm() {
    var form = new mini.Form("#form1");
    form.clear();
}

//左对齐
function leftAlignment() {
    var formTable = $("#formTable").children();
    console.log(formTable,'formTable');
    for(var i = 0; i < formTable.length; i++){
        // console.log($("#"+ formTable[i].title));
        $("#"+ formTable[i].id).css({ "left": "0px", "float": "none"});
    }
}
//右对齐
function rightAlignment() {
    var formTable = $("#formTable").children();
    for(var i = 0; i < formTable.length; i++){
        $("#"+ formTable[i].id).css({ "left": "auto", "right": "0px", "float": "right"});
    }
}
//上对齐
function alignTopEdge() {
    var formTable = $("#formTable").children();
    for(var i = 0; i < formTable.length; i++){
        $("#"+ formTable[i].id).css({ "top": "0px", "float": "none"});
    }
}
//下对齐
function bottomJustify() {
    var formTable = $("#formTable").children();
    for(var i = 0; i < formTable.length; i++){
        $("#"+ formTable[i].id).css({ "top": "auto", "bottom": "0px", "position": "absolute", "float": "none"});
    }
}
//刷新
function  refresh() {
    window.location.reload();
    // grid.reload();
    // mini.Form("#form1").reset();
    // mini.get("formTable").reload();
    // mini.get("layoutMode").reload();
}
//自动布局
function automaticLayout() {

}
//反向生成
function reverseGeneration() {

}
//合并
function merge() {

}

//属性栏显示/隐藏(使用fieldset时)
function toggleFieldSet(ck, id) {
    var dom = document.getElementById(id);
    dom.className = !ck.checked ? "hideFieldset" : "";
}

function changeFantSize() {
    var size = $('#changeFantSize').val();
    $('#li' + thisid).css('font-size', size + 'px')
}

function changebtdq(value) {
    switch (value) {
        case '左对齐':
            $('#li' + thisid).css('text-align', 'left');
            break;
        case '右对齐':
            $('#li' + thisid).css('text-align', 'right');
            break;
        case '居中':
            $('#li' + thisid).css('text-align', 'center');
            break;
        case '两端对齐':
            $('#li' + thisid).css('text-align', 'justify');
            break;

    }
}

var sxgriddata = {
    "total": 7, "rows": [
        {"name": "Name", "value": "Bill Smith", "group": "ID Settings", "editor": "text"},
        {"name": "Address", "value": "", "group": "ID Settings", "editor": "text"},
        {"name": "Age", "value": "40", "group": "ID Settings", "editor": "numberbox"},
        {"name": "Birthday", "value": "01/02/2012", "group": "ID Settings", "editor": "datebox"},
        {"name": "SSN", "value": "123-456-7890", "group": "ID Settings", "editor": "text"},
        {
            "name": "Email", "value": "bill@gmail.com", "group": "Marketing Settings", "editor": {
            "type": "validatebox",
            "options": {
                "validType": "email"
            }
        }
        },
        {
            "name": "FrequentBuyer", "value": "false", "group": "Marketing Settings", "editor": {
            "type": "checkbox",
            "options": {
                "on": true,
                "off": false
            }
        }
        }
    ]
};

function SaveFormData() {
    var form = new mini.Form("#form1");
    var data = form.getData();      //获取表单多个控件的数据
    var json = mini.encode(data);   //序列化成JSON
    // console.log(json,'json');
}

//表头唯一判断
var valFlag = -1;
function onComboValidation(e) {
    valFlag++;
    // var items = this.findItems(e.value);
    // console.log(items,'items');
    // console.log(properties_form,'properties_form');
    // console.log(properties_table,'properties_table');

    var lanyoutFlag = false;
    for(var i=0;i<properties_form.length;i++){
        if(properties_form[i].cTableField !=id_now && properties_form[i].hasOwnProperty("cRefObj")) {
            if(properties_form[i].cRefObj.lanyoutMent == "1" && valFlag>0) {
                lanyoutFlag = true;
            }
        }
    }
    for(var i=0;i<properties_table.length;i++){
        if(properties_table[i].cTableField !=id_now && properties_table[i].hasOwnProperty("cRefObj")) {
            if (properties_table[i].cRefObj.lanyoutMent == "1" && valFlag>0) {
                lanyoutFlag = true;
            }
        }
    }
    var obj = mini.get("lanyoutMent");
    if(lanyoutFlag && obj.getValue() == '1') {
        mini.alert('表头已存在');
        obj.setValue("2");
    }

    // if (!items || items.length == 0) {
    //     e.isValid = false;
    //     e.errorText = "输入值不在下拉数据中";
    // }
}
